$z-modal-backdrop: 1101;
$z-enketo-iframe-icon: 1100;
$z-modal-x: 10;

// -----------------------------------------------------------------------------
// common modal parts
// -----------------------------------------------------------------------------

.modal__backdrop {
  position: fixed;
  height: 100%;
  width: 100%;
  z-index: $z-modal-backdrop;
  top: 0px;
  left: 0px;
  background-color: rgba(0, 0, 0, 0.4) !important;
}

.modal {
  @include box-shadow-top;

  align-items: stretch;
  display: flex;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  min-width: 40%;
  max-width: 90%;
  max-height: 95%;
  overflow-x: auto;
  visibility: hidden;

  &.modal--open {
    visibility: visible;
  }

  &.modal--large {
    height: 80%;
    width: 80%;
    max-width: 1240px;

    .modal__content {
      height: 100%;
      width: 100%;
      display: flex;
      flex-direction: column;
    }

    .modal__body {
      flex-grow: 1;
      display: flex;
      flex-direction: column;

      .enketo-holder {
        flex-grow: 1;
        display: flex;
        flex-direction: column;
      }

      iframe {
        flex-grow: 1;
        border: 1px solid white;
        width: 100%;
      }
    }
  }
}

.modal__body {
  // we use margin for bottom to make it stack with modal__footer
  padding: 30px 30px 0;
  margin-bottom: 30px;

  // in some cases adding custom footer requires it to be inside modal__body and
  // then padding is not needed
  .modal__footer {
    padding: 0;
  }
}

.modal__content {
  overflow: auto;
  background-color: $white;
  width: 100%;
}

.modal__tabs {
  background: $cool-blue;
  color: $white;
}

.modal__header {
  min-height: 70px;
  background: $cool-blue;
  color: $white;
}

.modal__title {
  margin: 0px;
  padding: 24px 30px;
  font-size: 18px;
  line-height: 22px;
}

.modal__x {
  position: absolute;
  z-index: $z-modal-x;
  top: 0;
  right: 0;
  color: inherit;
  background-color: inherit;
  padding: 8px;
  margin: 11px;
  border-radius: 50%;
  font-size: 20px;
  cursor: pointer;

  i {
    display: block;
    font-size: 32px;
  }

  &:hover {opacity: 0.7;}
}

.modal__subheader {
  background: $cool-whitegray;
  padding: 20px 30px;
  margin: -30px -30px 20px;
  color: $cool-silver;

  i {
    margin: 2px 10px 10px 0;
    font-size: 32px;
    float: left;
  }
}

.modal__footer {
  padding: 0 30px 30px;
  margin-top: 20px;
  text-align: right;

  &::before,
  &::after {
    content: '';
    display: table;
    clear: both;
  }

  &:first-child {
    margin-top: 0;
    margin-bottom: 20px;
  }

  .modal__footer-button {
    @extend .mdl-button;
    text-transform: uppercase;

    &:not(:first-of-type) {
      margin-left: 10px;
    }

    &.modal__footer-button--primary {
      @extend .mdl-button--colored, .mdl-button--raised;
      padding-left: 40px;
      padding-right: 40px;
    }

    &.modal__footer-button--secondary {
      @extend .mdl-button--colored;
    }

    &.modal__footer-button--danger {
      @extend .mdl-button--colored, .mdl-button--danger;
    }

    &.modal__footer-button--back {
      border-radius: 2px;
      color: $cool-blue;
      border: 1px solid currentColor;
      opacity: 1;
      float: left;

      &:hover {
        opacity: 0.8;
        color: $cool-blue;
      }
    }
  }
}

.modal__hr {
  margin: 20px -30px;
  border: 0;
  background-color: $divider-color;
  height: 1px;
}

// -----------------------------------------------------------------------------
// custom parts and overrides
// -----------------------------------------------------------------------------

.modal.modal-submission {
  .modal__header {
    background-color: $cool-whitegray;
    color: $layout-text-color;
  }

  .form-modal {
    text-align: right;
    padding-bottom: 20px;
  }

  .mdl-button--raised + .mdl-button--icon {
    margin-left: 30px;
    overflow: visible;
  }

  .form-modal__group {
    display: flex;
    justify-content: space-between;
    margin-bottom: 20px;

    .switch--label-language,
    .switch--validation-status {
      width: 50%;
      text-align: left;

      label, .kobo-select {
        display: inline-block;
        vertical-align: middle;
      }

      label {
        margin-right: 12px;
      }
    }

    .switch--validation-status {
      width: 100%;
      text-align: right;
      .kobo-select {
        text-align: left;
      }
    }

    .switch--label-language + .switch--validation-status {
      width: 50%;
    }

    .kobo-select input {
      min-width: 100px;
    }

    .kobo-select {
      min-width: 120px;
    }
  }

  .submission-pager {
    a {
      display: inline-block;
      cursor: pointer;

      &:first-child {
        padding-left: 0;
      }

      .k-icon {
        display: inline-block;
        vertical-align: middle;
      }
    }
  }

  .submission-actions {
    .checkbox {
      display: inline-block;
      vertical-align: middle;
      margin-right: 40px;
    }

    .checkbox__label {
      white-space: nowrap;
    }
  }

  .submission--warning {
    margin-bottom: 30px;
    padding: 10px;
    background: $cool-whitegray;
    text-align: center;
    line-height: 1em;

    i {
      color: $cool-orange;
      font-size: 40px;
      margin-right: 10px;
      vertical-align: middle;
      display: inline-block;
    }

    span {
      line-height: 1.4em;
      display: inline-block;
      vertical-align: middle;
      width: calc(100% - 60px);
    }

    + .submission--warning {
      margin-top: -30px;
      border-top: 1px solid $divider-color;
    }
  }
}

.enketo-holder {
  // resets modal window paddings
  margin: -30px -30px;

  .enketo-loading-message {
    p {
      text-align: center;
      font-weight: 600;
    }

    i:before {
      color: #3FA2EE;
      font-size: 20px;
    }
  }

  .touch & {
    width: 94%;
    left: 3%;
    margin-left: 0px;
    -webkit-overflow-scrolling: touch;
    overflow-y: scroll;
  }
}

.enketo-iframe-icon {
  color: #fff;
  background-image: url("~/jquery-ui/themes/humanity/images/ui-icons_ffffff_256x240.png");
  background-color: #C6CBD0;
  background-position: -81px -129px;
  position: absolute;
  right: 6px;
  top: 6px;
  border-radius: 3px;
  z-index: $z-enketo-iframe-icon;
  width: 15px;
  height: 15px;
  cursor: pointer;
}

.project-settings {
  // make sure it doesn't get too small (but only inside modal)
  .modal & {
    width: 100%;

    @media screen and (min-width: 768px) {
      min-width: 600px;
    }
  }

  .intro {
    margin-bottom: 20px;
    text-align: left;
  }

  // override two columns to rows
  &.project-settings--narrow {
    .form-modal__item--sector,
    .form-modal__item--country {
      width: 100%;
      float: none;

      .kobo-select {
        margin-right: 0;
      }
    }
  }

  $buttons-spacing: 10px;

  .form-modal__item--form-source-buttons {
    margin: 0 auto;
    max-width: 500px;

    button {
      display: inline-block;
      vertical-align: top;
      border: 1px solid $divider-color;
      background: $cool-whitegray;
      border-radius: 4px;
      color: $cool-gray;
      cursor: pointer;
      margin: 0.5*$buttons-spacing;
      padding: $buttons-spacing;
      width: calc(50% - #{$buttons-spacing});
      min-height: 120px;

      @media screen and (min-width: 768px) {
        margin: $buttons-spacing;
        padding: 2*$buttons-spacing;
        width: calc(50% - #{2*$buttons-spacing});
      }

      i {
        display: block;
        margin: 0 auto;
        font-size: 48px;
      }

      &:hover {
        color: $cool-blue;
        border-color: $cool-blue;
        i {color: $cool-blue;}
      }
    }
  }

  .dropzone {
    background: $cool-whitegray;
    padding: 30px;
    border: 2px dashed $divider-color;
    cursor: pointer;
    border-radius: 6px;
    text-align: center;

    i {
      display: block;
      margin: 0 auto;
      font-size: 72px;
      opacity: 0.5;
    }

    .loading {
      font-size: inherit;
    }

    .loading i {
      font-size: 36px;
      margin-top: 20px;
      margin-bottom: 16px;
    }

    &:hover {border-color: $cool-blue;}
    &.dropzone-active {border-color: $cool-blue;}
    &.dropzone-reject {border-color: $cool-red;}
  }
}

@media screen and (min-height: 600px) {
  // on bigger screens make templates-list scrollable to always display back/next buttons
  .project-settings.project-settings--choose-template {
    .templates-list {
      max-height: 380px;
      overflow-y: auto;
    }
  }
}

.form-modal__item--http-headers {
  .form-modal__item--http-header-row {
    margin-top: 10px;

    input {
      width: calc(50% - 20px);
      background-color: rgba($black, 0.05);
      padding-left: 5px;
      padding-right: 5px;

      &:not(:first-child) {
        margin-left: 10px;
      }
    }
  }

  .http-header-add,
  .http-header-row-remove {
    height: 30px;
    min-height: 30px;
    line-height: 30px;

    .k-icon {
      font-size: 1.5em;
      vertical-align: middle;
    }
  }

  .http-header-add {
    @extend .mdl-button, .mdl-button--raised, .mdl-button--colored;
    background: $cool-gray;
    vertical-align: middle;
    padding: 0 12px 0 6px;

    &:hover {background: darken($cool-gray, 10%);}
  }

  .http-header-row-remove {
    @extend .mdl-button, .mdl-button--icon;
    width: 30px;
    vertical-align: top;
    padding: 0;
    &:hover {color: $cool-red;}
  }
}

.form-modal--translation-settings {
  @media (min-width: 600px) {
    min-width: 500px;
  }

  .form-view__cell--translation-note {
    padding-bottom: 20px;

    p {
      margin: 0;
    }
  }
  .form-view__cell--translation {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-top: 1px solid $divider-color;
    padding: 6px 0px;

    .form-view__cell--translation-name .form-view__icon-button {
      opacity: 0;
      visibility: hidden;
      transition: 250ms;
    }

    &:hover .form-view__cell--translation-name .form-view__icon-button {
      opacity: 1;
      visibility: visible;
    }
  }

  .form-view__cell--translation-actions {
    white-space: nowrap;
  }

  .form-view__label--default-language {
    display: inline;
    font-weight: 700;
    margin-left: 6px;
  }

  .form-view__cell--add-language {
    padding-top: 20px;
    text-align: right;
    border-top: 1px solid $divider-color;
  }

  .form-view__cell--add-language-form,
  .form-view__cell--update-language-form {
    background: $cool-whitegray;
    padding: 15px;
    position: relative;

    .form-view__link--close {
      position: absolute;
      right: 0px;
      top: 6px;

      i {
        font-size: 24px;
      }
    }
  }

  .form-view__cell--add-language-form {
    margin-top: 20px;
  }

  .form-view__form--add-language-fields {
    display: flex;
    justify-content: space-between;

    .form-view__cell {
      &:not(:first-child) {margin-left: 10px;}
      &.form-view__cell--lang-name {flex: 3;}
      &.form-view__cell--lang-code {flex: 2;}
      &.form-view__cell--submit-button {padding-top: 10px;}
    }
  }
}

.form-modal--translation-table {
  // assumption: parent is display flex
  flex: 1;
  height: 100%;
  display: flex;
  flex-direction: column;
  width: 100%;
  margin: 0;

  .translation-table-container {
    flex: 1;
    overflow-y: auto;
    border: 1px solid $divider-color;
  }

  .form-view__cell--add-language-form,
  .form-view__cell--update-language-form {
    background: $cool-whitegray;
    padding: 15px;
    position: relative;

    .form-view__link--close {
      position: absolute;
      right: 0px;
      top: 6px;

      i {
        font-size: 24px;
      }
    }
  }

  .form-view__cell--update-language-form {
    max-width: 70%;
    margin-left: auto;
  }

  .form-view__form--add-language-fields {
    display: flex;
    justify-content: space-between;

    .form-view__cell {
      &:not(:first-child) {margin-left: 10px;}
      &.form-view__cell--lang-name {flex: 3;}
      &.form-view__cell--lang-code {flex: 2;}
      &.form-view__cell--submit-button {padding-top: 10px;}
    }
  }

  .ReactTable {
    width: 100%;

    .rt-thead.-header {
      box-shadow: none;
      border-bottom: 2px solid $divider-color;
    }

    .rt-thead > .rt-tr,
    .rt-tr-group > .rt-tr {
      .rt-td {
        white-space: normal;
      }
      > .rt-th:first-child,
      > .rt-td:first-child {
        min-width: 30%;
        color: lighten($cool-gray, 10%);
      }

      > .rt-th:last-child,
      > .rt-td:last-child {
        min-width: 70%;
      }
      .translation {
        background: lighten($cool-green, 41%);
        color: lighten($black, 15%);
        padding: 0px;
        textarea {
          padding: 8px;
          border: none;
          background: transparent;
          width: 100%;
          &:focus {
            background: lighten($cool-green, 35%);
          }
        }
      }
    }
  }
}

@media screen and (max-width: 767px) {
  .modal.modal--open {
    min-width: 90%;
    max-width: 90%;
  }
}
